package com.qf.mapper;

import com.qf.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

// dao --> mapper
public interface UserMapper2 {

    //自动映射 - 查询结果列必须和目标对象的属性名一致
    @Select("select * from user")

    //手动映射
    @ResultMap("userMap2")
    List<User> findAll();

    @Select("select * from user where id=#{id}")
    @ResultMap("userMap2")
    User findById(Integer id);

    @Insert("insert into user (name,gender,age,u_name,bir) values (#{name},#{gender},#{age},#{uName},#{bir})")

    //获取新增后的自增主键值
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int insert(User user);

    @Update("update user set name=#{name},gender=#{gender},u_name=#{uName} where id=#{id}")
    int update(User user);

    @Delete("delete from user where id=#{id}")
    int delete(Integer id);

    List<User> findByConditions(User user);

    List<User> findByNameAndAge(@Param("name") String name, @Param("age")Integer age);

    List<User> findByIds(List<Integer> ids);
    List<User> findByIds2(Integer... ids);
}
